using System;

namespace NET.Library.Manipulation
{
	/// <summary>
    /// DateTime Manipulation Object.
	/// </summary>
	public class DateTimes
	{
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Enumerator used with the DateTime.CompareTo method which runs a comparison against 
        /// two dates and returns the result as an integer.
        /// </summary>
        /// <remarks>
        /// The CompareTo method compares the value of a DateTime instance to a specified DateTime 
        /// value and returns an integer that indicates whether this instance is earlier than (-1), 
        /// the same as (0), or later than (1) the specified DateTime value.
        /// </remarks>
        /// <example>
        /// DateTime dateNow = DateTime.Now
        /// DateTime dateYesterday = dateNow.AddDays(-1);
        /// DateComparisonResult dateComparison = (DateComparisonResult)dateNow.CompareTo(DateTime);
        /// 
        /// The value of dateComparison would be equal to DateComparisonResult.Earlier.
        /// </example>
        ///----------------------------------------------------------------------------------
        public enum DateComparisonResult
        {
            /// <summary>
            /// 
            /// </summary>
            Earlier = -1,
            /// <summary>
            /// 
            /// </summary>
            Later = 1,
            /// <summary>
            /// 
            /// </summary>
            TheSame = 0
        };

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Returns string format for UK Short Date (dd/MM/yyyy)
        /// </summary>
        ///----------------------------------------------------------------------------------
        public const string UKShortDateFormat = "dd/MM/yyyy";

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Returns string format for US Short Date (MM/dd/yyyy)
        /// </summary>
        ///----------------------------------------------------------------------------------
        public const string USShortDateFormat = "MM/dd/yyyy";

        ///----------------------------------------------------------------------------------
        /// returns date values 
        ///----------------------------------------------------------------------------------
        public static DateTime dateGetVal(object Value)
		{
			return Value == DBNull.Value ? DateTime.MinValue : (DateTime)Value;
		}

        ///----------------------------------------------------------------------------------
        /// Minimum DateTime property 
        ///----------------------------------------------------------------------------------
        public static DateTime minDateTime
        {
            get { return new DateTime(1900, 1, 1, 0, 0, 0); }
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Checks if a string is a DateTime value.
        /// </summary>
        /// <param name="stringToCheck"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static bool IsDate(string stringToCheck)
        {
            DateTime resultDate;
            bool isDate = true;
            if (stringToCheck == null)
            {
                stringToCheck = "";
            }
            try
            {
                resultDate = DateTime.Parse(stringToCheck);
            }
            catch
            {
                isDate = false;
            }
            return isDate;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Checks if a string is a DateTime value and returns a DateTime value.
        /// </summary>
        /// <param name="stringToCheck"></param>
        /// <param name="resultDate">If the string value is not a valid DateTime value then the DateTime.MinValue is returned
        /// otherwise the string value is converted into a DateTime value and returned.</param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static bool IsDate(string stringToCheck, out DateTime resultDate)
        { 
            bool isDate = true;
            if (stringToCheck == null) 
            {
                stringToCheck = ""; 
            } 
            try 
            {
                resultDate = DateTime.Parse(stringToCheck); 
            } 
            catch 
            { 
                resultDate = DateTime.MinValue; isDate = false; 
            } 
            return isDate; 
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Get the name of the month
        /// </summary>
        /// <param name="monthNum">Pass in a value between 1 and 12 (1 to return January and so on...)</param>
        /// <returns></returns>
        /// <example>
        /// string myBirthdayMonth = MonthName(11);
        /// Will set the variable myBirthdayMonth to equal November.
        /// </example>
        ///----------------------------------------------------------------------------------
        public static string MonthName(int monthNum)
        {
            return new DateTime(1, monthNum, 1).ToString("MMMM");
        }
	}
}
